/*********************************************************************************
Organization 					: 				Georgia Institute of Technology
  
Institute 						:				Cognitive Computing Group(CCL)
 
Authors							: 				Santiago Ontanon, Kinshuk Mishra
 												Neha Sugandh 
 												
Class							:				StandGroundBOPlan
 
Function						: 				Provides a Plan for executing 
												a stand ground plan 
****************************************************************************/
package planninglanguage.plans;

import org.jdom.Element;

import planninglanguage.conditions.Condition;
import planninglanguage.conditions.UnitExistsCondition;
import util.XMLWriter;
import base.ProxyBot;

public class StandGroundBOPlan extends BasicOperatorPlan implements Cloneable {
	
	public StandGroundBOPlan(int a_unitID,Condition a_precondition,Condition a_aliveCondition,Condition a_successCondition)
	{
		super(a_precondition,a_aliveCondition,a_successCondition);
		m_unitID=a_unitID;
		m_precondition = new UnitExistsCondition(m_unitID);
		m_aliveCondition = new UnitExistsCondition(m_unitID);
		m_successCondition = null;
	}
	
	public StandGroundBOPlan(int a_unitID,Condition a_precondition,Condition a_aliveCondition,Condition a_successCondition, Plan a_parent)
	{
		super(a_precondition,a_aliveCondition,a_successCondition);
		m_unitID=a_unitID;
		m_precondition = new UnitExistsCondition(m_unitID);
		m_aliveCondition = new UnitExistsCondition(m_unitID);
		m_successCondition = null;
		m_parent = a_parent;
	}
	
	public Object clone()
	{
		StandGroundBOPlan l_p =new StandGroundBOPlan(m_unitID,null,null,null, m_parent);
		l_p.setContext(m_context);
		l_p.m_originalUnit = m_originalUnit;
		return l_p;
	}

	public boolean send()
	{
		ProxyBot.getProxyBot().standGround(m_unitID);		
		return true;
	}
	
	public String toString(int tabs) {
		String str= "";
		int i;
		
		for(i=0;i<tabs;i++) str = str + "  ";
		str = str + "StandGroundBOPlan(status = " + STATUS_NAME[m_status] + " , unitID = " + m_unitID +  " ) ";
		str = str + conditionsToString(tabs);
		return str;
	}		
	
	public boolean sameGoal(Object other)
	{
		if (getClass() != other.getClass()) return false;

		StandGroundBOPlan o = (StandGroundBOPlan) other;
		   
		if (m_unitID!=o.m_unitID) return false;	
		return true;
	}		
	
	public void writeXML(XMLWriter w) {
		w.tag(super.XMLopenTag() + " type=\"" + 
				this.getClass().getSimpleName() + "\"");
		{			
			super.writeBOPlanAttrsXML(w);
		}
		w.tag(super.XMLcloseTag());
	}
	
	protected static StandGroundBOPlan loadFromXML(Element e) {
		StandGroundBOPlan plan = new StandGroundBOPlan(-1, null, null, null);
		return plan;
	}
}
